package com.ruoyi.web.controller.system;

import java.util.List;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.ServiceType;
import com.ruoyi.system.service.IServiceTypeService;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 信用服务类型Controller
 * 
 * @author Jack
 * @date 2025-07-03
 */
@Controller
@RequestMapping("/system/type")
public class ServiceTypeController extends BaseController
{
    private String prefix = "system/type";

    @Autowired
    private IServiceTypeService serviceTypeService;

    @RequiresPermissions("system:type:view")
    @GetMapping()
    public String type()
    {
        return prefix + "/type";
    }

    /**
     * 查询信用服务类型列表
     */
    @RequiresPermissions("system:type:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(ServiceType serviceType)
    {
        startPage();
        List<ServiceType> list = serviceTypeService.selectServiceTypeList(serviceType);
        return getDataTable(list);
    }

    /**
     * 导出信用服务类型列表
     */
    @RequiresPermissions("system:type:export")
    @Log(title = "信用服务类型", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(ServiceType serviceType)
    {
        List<ServiceType> list = serviceTypeService.selectServiceTypeList(serviceType);
        ExcelUtil<ServiceType> util = new ExcelUtil<ServiceType>(ServiceType.class);
        return util.exportExcel(list, "信用服务类型数据");
    }

    /**
     * 新增信用服务类型
     */
    @RequiresPermissions("system:type:add")
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存信用服务类型
     */
    @RequiresPermissions("system:type:add")
    @Log(title = "信用服务类型", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(ServiceType serviceType)
    {
        return toAjax(serviceTypeService.insertServiceType(serviceType));
    }

    /**
     * 修改信用服务类型
     */
    @RequiresPermissions("system:type:edit")
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") Long id, ModelMap mmap)
    {
        ServiceType serviceType = serviceTypeService.selectServiceTypeById(id);
        mmap.put("serviceType", serviceType);
        return prefix + "/edit";
    }

    /**
     * 修改保存信用服务类型
     */
    @RequiresPermissions("system:type:edit")
    @Log(title = "信用服务类型", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(ServiceType serviceType)
    {
        return toAjax(serviceTypeService.updateServiceType(serviceType));
    }

    /**
     * 删除信用服务类型
     */
    @RequiresPermissions("system:type:remove")
    @Log(title = "信用服务类型", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(serviceTypeService.deleteServiceTypeByIds(ids));
    }
}
